package com.tentact.coolmeetingtest.support;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 星环
 * @date 2023/2/15 0:56:40
 * @description
 */
public class MyMessage {
    public boolean isDestFunc;
    public String dispatchDest;
    public Map<String,Object> params;

    public static MyMessage of(boolean isDestFunc,String dispatchDest,Object... params){
        if(params.length % 2 != 0){
            System.err.println("[error]:building mymessage : param length is not even -> valued " + params.length);
            for (Object param : params) {
                System.err.println(param);
            }
            new Exception().printStackTrace();
            return null;
        }
        MyMessage message = new MyMessage();
        Map<String,Object> map = new HashMap<>();
        System.out.println("[log] start to build message params : length is " + params.length);
        for(int i = 0;i < params.length;i += 2){
            map.put((String) params[i],params[i+1]);
            System.out.println("[log] putted kv " + params[i] + "->" + params[i+1]);
        }
        message.isDestFunc = isDestFunc;
        message.dispatchDest = dispatchDest;
        message.params = map;
        return message;
    }
}
